"use strict";
cc._RF.push(module, '3f339rEMNhD0Jf2RykkLG6V', 'GameCameraControl');
// scripts/GameCameraControl.js

"use strict";

var t = require;
var e = module;
var o = exports;

var _i,
    n = void 0 && (void 0).__extends || (_i = function i(t, e) {
  return (_i = Object.setPrototypeOf || {
    __proto__: []
  } instanceof Array && function (t, e) {
    t.__proto__ = e;
  } || function (t, e) {
    for (var o in e) {
      Object.prototype.hasOwnProperty.call(e, o) && (t[o] = e[o]);
    }
  })(t, e);
}, function (t, e) {
  function o() {
    this.constructor = t;
  }

  _i(t, e), t.prototype = null === e ? Object.create(e) : (o.prototype = e.prototype, new o());
}),
    a = void 0 && (void 0).__decorate || function (t, e, o, i) {
  var n,
      a = arguments.length,
      r = a < 3 ? e : null === i ? i = Object.getOwnPropertyDescriptor(e, o) : i;
  if ("object" == typeof Reflect && "function" == typeof Reflect.decorate) r = Reflect.decorate(t, e, o, i);else for (var s = t.length - 1; s >= 0; s--) {
    (n = t[s]) && (r = (a < 3 ? n(r) : a > 3 ? n(e, o, r) : n(e, o)) || r);
  }
  return a > 3 && r && Object.defineProperty(e, o, r), r;
};

Object.defineProperty(o, "__esModule", {
  value: !0
});

var r = cc._decorator,
    s = r.ccclass,
    l = r.property,
    c = function (t) {
  function e() {
    var e = null !== t && t.apply(this, arguments) || this;
    return e.node_topFrame = null, e._gameControl = null, e.camera = null, e.isGameStart = !1, e.nDistance = 0, e.MaxRatio = 1.3, e.posTopFrame = null, e.isNormal = !1, e.nNormalTime = 0, e.normalTopPos = cc.v2(0, 0), e.normalTopScale = 0, e.normalNodeX = 0, e.nMovePosX = null, e;
  }

  return n(e, t), e.prototype.onLoad = function () {
    this.camera = this.node.getComponent(cc.Camera);
  }, e.prototype.init = function (t) {
    this._gameControl = t, this.isNormal = !1, this.posTopFrame = this.node_topFrame.position;
  }, e.prototype.onGameStart = function () {
    var t = this;
    this.nDistance = this.getCarDistance(), this.isGameStart = !0, this.isNormal = !1, this.node_topFrame.getComponent(cc.Widget).enabled = !1, this.scheduleOnce(function () {
      if (!t.isNormal) {
        t.nNormalTime = (t.camera.zoomRatio - 1) / .01;
        var e = Math.abs(t.node_topFrame.position.x - t.posTopFrame.x) / t.nNormalTime,
            o = Math.abs(t.node_topFrame.position.y - t.posTopFrame.y) / t.nNormalTime;
        t.normalTopPos = cc.v2(e, o), t.normalTopScale = Math.abs(t.node_topFrame.scale - 1) / t.nNormalTime, t.normalNodeX = Math.abs(t.node.position.x) / t.nNormalTime;
      }

      t.isNormal = !0;
    }, 8);
  }, e.prototype.onGameOver = function () {
    if (this.isGameStart = !1, !this.isNormal) {
      this.nNormalTime = (this.camera.zoomRatio - 1) / .01;
      var t = Math.abs(this.node_topFrame.position.x - this.posTopFrame.x) / this.nNormalTime,
          e = Math.abs(this.node_topFrame.position.y - this.posTopFrame.y) / this.nNormalTime;
      this.normalTopPos = cc.v2(t, e), this.normalTopScale = Math.abs(this.node_topFrame.scale - 1) / this.nNormalTime, this.normalNodeX = Math.abs(this.node.position.x) / this.nNormalTime;
    }

    this.isNormal = !0;
  }, e.prototype.lateUpdate = function () {
    if (this.isNormal) this.updateNormal();else if (this.isGameStart) {
      var t = 1 + 1 * (1 - this.getCarDistance() / this.nDistance);

      if (t > 1) {
        var e = this.getTargetPosX();

        if (this.node.position = cc.v3(e, 0, this.node.position.z), this.node_topFrame.x = e, t <= this.MaxRatio) {
          this.camera.zoomRatio = t, this.node_topFrame.scale = 1 / t;
          var o = cc.winSize.height * (t - 1);
          this.node_topFrame.y = this.posTopFrame.y - o / 2;
        }
      }
    }
  }, e.prototype.updateNormal = function () {
    1 != this.node_topFrame.scale && (this.node_topFrame.scale < 1 ? (this.node_topFrame.scale += this.normalTopScale, this.node_topFrame.scale > 1 && (this.node_topFrame.scale = 1)) : this.node_topFrame.scale > 1 && (this.node_topFrame.scale -= this.normalTopScale, this.node_topFrame.scale < 1 && (this.node_topFrame.scale = 1)));
    var t = this.node_topFrame.position.x;
    t != this.posTopFrame.x && (t < this.posTopFrame.x ? (t += this.normalTopPos.x) > this.posTopFrame.x && (t = this.posTopFrame.x) : t > this.posTopFrame.x && (t -= this.normalTopPos.x) < this.posTopFrame.x && (t = this.posTopFrame.x));
    var e = this.node_topFrame.position.y;
    e != this.posTopFrame.y && (e < this.posTopFrame.y ? (e += this.normalTopPos.y) > this.posTopFrame.y && (e = this.posTopFrame.y) : e > this.posTopFrame.y && (e -= this.normalTopPos.y) < this.posTopFrame.y && (e = this.posTopFrame.y)), this.node_topFrame.position = cc.v3(t, e, 0);
    var o = this.node.position.x;
    0 != o && 0 != o && (o < 0 ? (o += this.normalNodeX) > 0 && (o = 0) : o > 0 && (o -= this.normalNodeX) < 0 && (o = 0)), this.node.position = cc.v3(o, 0, this.node.position.z);
    var i = this.camera.zoomRatio;
    1 != i && (i < 1 ? (i += .01) > 1 && (i = 1) : i > 1 && (i -= .01) < 1 && (i = 1)), this.camera.zoomRatio = i;
  }, e.prototype.getCarDistance = function () {
    var t = this._gameControl._carLeftView.getCarToWorldPos(cc.Vec2.ZERO).x,
        e = this._gameControl._carRightView.getCarToWorldPos(cc.Vec2.ZERO).x;

    return Math.abs(t - e);
  }, e.prototype.getCarCentralX = function () {
    var t = this.getCarDistance();
    return this._gameControl._carLeftView.getCarPos().x + t / 2;
  }, e.prototype.getCarPos = function () {
    return this._gameControl._carLeftView.getCarPos();
  }, e.prototype.getTargetPosX = function () {
    var t = this._gameControl._carLeftView.getCarToWorldPos(cc.v2(this.getCarDistance() / 2, 0)),
        e = this.node.parent.convertToNodeSpaceAR(t);

    return null === this.nMovePosX && (this.nMovePosX = e.x), e.x = e.x - this.nMovePosX, e.x > 100 ? e.x = 100 : e.x < -100 && (e.x = -100), e.x;
  }, a([l(cc.Node)], e.prototype, "node_topFrame", void 0), a([s], e);
}(cc.Component);

o["default"] = c;

cc._RF.pop();